﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace QuanLyThuoc.DAL
{
   public class BenhNhanDAL:KetNoiDAL
    {
       public DataTable SelectAll_BenhNhan()
       {
           SqlCommand cmd = new SqlCommand("SelectAll_BenhNhan", Connect());
            cmd.CommandType=CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
       }
       public DataTable Search_BenhNhanByDK(string keyword)
       {
           SqlCommand cmd = new SqlCommand("SearchByConditionBN", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@keywrod", keyword);
           
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable SelectID_BenhNhanMAX()
       {
           
           SqlCommand cmd = new SqlCommand("SelectID_BenhNhanMAX", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           
           return dt;
       }
       public DataTable SelectID_BenhNhan(int MaBN)
       {
           SqlCommand cmd = new SqlCommand("SelectAll_BenhNhan", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDBN", MaBN);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable Search(int MaBN, string TenBN, string Gioi, string NamSinh, string DiaChi, string DienThoai)
       {
           SqlCommand cmd = new SqlCommand("Search_BenhNhan", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDBN", MaBN);
           cmd.Parameters.AddWithValue("@TenBN", TenBN);
           cmd.Parameters.AddWithValue("@Gioi", Gioi);
           cmd.Parameters.AddWithValue("@NamSinh", NamSinh);
           cmd.Parameters.AddWithValue("@DiaChi", DiaChi);
           cmd.Parameters.AddWithValue("@DienThoai", DienThoai);

           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public int InsertBenhNhan(string TenBN, string Gioi, string NamSinh, string DiaChi, string DienThoai)
       {
          
               SqlCommand cmd = new SqlCommand("Insert_BenhNhan", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               //cmd.Parameters.AddWithValue("@IDBN", MaBN);
               cmd.Parameters.AddWithValue("@TenBN", TenBN);
               cmd.Parameters.AddWithValue("@Gioi", Gioi);
               cmd.Parameters.AddWithValue("@NamSinh", NamSinh);
               cmd.Parameters.AddWithValue("@DiaChi", DiaChi);
               cmd.Parameters.AddWithValue("@DienThoai", DienThoai);
            return   cmd.ExecuteNonQuery();
         
       }
       public int UpdateBenhNhan(int MaBN, string TenBN, string Gioi, string NamSinh, string DiaChi, string DienThoai)
       {
          
               SqlCommand cmd = new SqlCommand("Update_BenhNhan", Connect());
               cmd.CommandType = CommandType.StoredProcedure;

               cmd.Parameters.AddWithValue("@IDBN", MaBN);
               cmd.Parameters.AddWithValue("@TenBN", TenBN);
               cmd.Parameters.AddWithValue("@Gioi", Gioi);
               cmd.Parameters.AddWithValue("@NamSinh", NamSinh);
               cmd.Parameters.AddWithValue("@DiaChi", DiaChi);
               cmd.Parameters.AddWithValue("@DienThoai", DienThoai);
             return  cmd.ExecuteNonQuery();
          
       }
       public int DeleteBenhNhan(int MaBN)
       {
         
               SqlCommand cmd = new SqlCommand("Delete_BenhNhan", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDBN", MaBN);
             return  cmd.ExecuteNonQuery();
         
       }
    }
}
